package com.seven.dao;

import java.util.List;

import com.seven.entity.Worker;

//员工dao
public class WorkerDao extends BaseDao{
	/**
	 * 添加员工
	 */
	public int addWorker(Worker worker) {
		String sql = "insert into worker(worker_name,worker_username,worker_password,worker_score,worker_state)values(?,?,?,?,?)";
		Object[] ob = {worker.getWorker_name(),worker.getWorker_username(),worker.getWorker_password(),worker.getWorker_score(),worker.getWorker_state()};
		return super.update(sql, ob);
		
	}
	
	/**
	 * 更新员工
	 */
	public int updateWorker(Worker worker) {
		String sql = "update worker set worker_name = ?,worker_username = ?,worker_password = ?,worker_score = ? ,worker_state = ? where worker_id=?";
		Object[] ob = {worker.getWorker_name(),worker.getWorker_username(),worker.getWorker_password(),worker.getWorker_score(),worker.getWorker_state(),worker.getWorker_id()};
		return super.update(sql, ob);
		
	}
	
	/**
	 * 更改员工状态
	 */
	public int setWorker_state(Worker worker) {
		String sql = "update worker set worker_state = ? where worker_id = ?";
		Object[] ob = {worker.getWorker_state(),worker.getWorker_id()};
		return super.update(sql, ob);
	}
	
	/**
	 * 删除员工
	 */
	public int deleteWorker(Worker worker) {
		System.out.println("daodaodao"+worker.getWorker_id());
		String sql = "update worker set worker_state = -1 where worker_id = ?";
		int ob = worker.getWorker_id();
		return super.update(sql, ob);
		
	}
	
	/**
	 * 查询所有员工
	 */
	public List<Worker> selectAllWorker() {
		String sql = "select * from worker where worker_state in (0,1)";
		return super.query2(sql, Worker.class);
		
	}
	
	/**
	 * 通过员工id查询员工
	 */
	public List<Worker> selectByWorker_id(Worker worker) {
		String sql = "select * from worker where worker_id = ?";
		int ob = worker.getWorker_id();
		return super.query2(sql, Worker.class, ob);
		
	}
	
	/**
	 * 通过员工姓名查询员工
	 */
	public List<Worker> selectByWorker_name(Worker worker) {
		String sql = "select * from worker where worker_name = ?";
		String ob = worker.getWorker_name();
		return super.query2(sql, Worker.class, ob);
		
	}
	
	/**
	 * 通过员工账号查询员工
	 */
	public List<Worker> selectByWorker_username(Worker worker) {
		String sql = "select * from worker whrere worker_username = ? and worker_password = ?";
		Object[] ob = {worker.getWorker_username(),worker.getWorker_password()};
		return super.query2(sql, Worker.class, ob);
		
	}
	
	/**
	 * 查询出空闲员工
	 */
	public List<Worker> selectByWorker_state0() {
		String sql = "select * from worker whrere worker_state = 0";
		
		return super.query2(sql, Worker.class);
		
	}
	
	/**
	 * 查询出忙碌员工
	 */
	public List<Worker> selectByWorker_state1() {
		String sql = "select * from worker whrere worker_state = 1";
		
		return super.query2(sql, Worker.class);
		
	}
	
	/**
	 * 通过员工id查询出员工姓名
	 */
	public List<Worker> selectNameById(int worker_id) {
		String sql = "select * from worker where worker_id = ?";
		int ob = worker_id;
		return super.query2(sql, Worker.class, ob);
	}
}
